<?php
/*
 * File name : Pledge.php
 * Description : Allows the Donor to subscribe to a pledge based donation.
 * Created By : Pratibha Awasthi
 * 
 */
include_once "basePage.php";

class Pledge extends basePage{
	
	public function current_pledges(){
		
		$con = mysql_connect('localhost','pa_user','secret_password');
			if (!$con){
		  		die('Could not connect: ' . mysql_error());
		  	}
		  
			mysql_select_db("TGS_GM_RESERVATION", $con);
			
			session_start();
			$userid = $_SESSION['userid'];
			
			$result_curr = mysql_query("SELECT * FROM TGS_GM_RESERVATION.tblsubscriberpledge where tblSubscriber_SubscriberID = (SELECT SubscriberID FROM TGS_GM_RESERVATION.tblsubscriber WHERE UserID = '{$userid}')");
			$row_curr = mysql_fetch_array($result_curr);
			
			$result = mysql_query("SELECT * FROM TGS_GM_RESERVATION.tblsubscriberpledge where tblSubscriber_SubscriberID = (SELECT SubscriberID FROM TGS_GM_RESERVATION.tblsubscriber WHERE UserID = '{$userid}')");
			echo "<h2><br/> Pledge Based Donation</h2> <br/> <br/>";
			
			if($row_curr['tblSubscriber_SubscriberID'] == NULL){
				echo "<h3> You currently do not have any Pledge Based donations </h3>";
				echo "<br/> <br/> <h2> <a href= 'http://localhost/good-mojo-donation/trunk/src/NewPledge.php'> Click Here </a> to Sign Up for a New Pledge based donation </h2> ";
			}
			else{
				
				echo <<<EPRINT
				
					<h3> Ongoing Pledge Based donations </h3> <br/><br/>
					<table class = 'pledgeprofile'>
					<tr class= "pledgehead"> <td> Agency </td> <td> Frequency </td> <td> Amount </td> <td> Start Date </td> <td> End date </td> <tr>
					
EPRINT;

				//$result = mysql_query("SELECT * FROM TGS_GM_RESERVATION.tblsubscriberpledge where tblSubscriber_SubscriberID = (SELECT SubscriberID FROM TGS_GM_RESERVATION.tblsubscriber WHERE UserID = '{$userid}')");
				while($row = mysql_fetch_array($result)){
					
					   $agencyid = $row['AgencyID'];
					   $frequencyid = $row['FrequencyID'];
						
						$agencyname =  mysql_query("SELECT Name FROM TGS_GM_RESERVATION.tblagency where ID = '{$agencyid}'");
						$agencyname = mysql_fetch_array($agencyname);
						$frequencyname = mysql_query("SELECT FrequencyType FROM TGS_GM_RESERVATION.lkpfrequency where FrequencyID = '{$frequencyid}'");
						$frequencyname = mysql_fetch_array($frequencyname);
						
						
						echo <<<EPRINT
						
						<tr> <td> {$agencyname['Name']} </td> <td> {$frequencyname['FrequencyType']} </td> <td> {$row['Dollars']} </td> <td> {$row['StartDate']} </td> <td> {$row['EndDate']} </td> <tr>

EPRINT;
				}
				echo "</table>";
	
				mysql_close($con);
				
				echo "<br/> <br/> <h2> <a href= 'http://localhost/good-mojo-donation/trunk/src/NewPledge.php'> Click Here </a> to Sign Up for a New Pledge based donation </h2> ";
				
			}			
	}
}


$page = new Pledge();
$page->header();
$page->top_menu_donor();
$page->current_pledges();
$page->footer();

?>